import type { AuthApi } from '#/api/types';

import { Http as http } from '#/api/http';

/**
 * 用户登录
 * @param data 登录参数
 */
export async function loginApi(data: AuthApi.LoginParams) {
  return http.post<AuthApi.LoginResult>('/auth/login', data);
}

/**
 * 刷新访问令牌
 */
export async function refreshTokenApi() {
  return http.refreshToken<AuthApi.RefreshTokenResult>('/auth/refresh');
}

/**
 * 用户登出
 */
export async function logoutApi() {
  return http.post<string>('/auth/logout');
}

/**
 * 获取权限列表
 */
export async function getPermissionListApi() {
  return http.get<string[]>('/auth/permission/list');
}

/**
 * 获取菜单列表
 */
export async function getRouteListApi() {
  return http.get<AuthApi.RouteItem[]>('/auth/route/list');
}

/**
 * 检查权限
 * @param permissionCode 权限编码
 */
export async function checkPermissionApi(permissionCode: string) {
  return http.post('/auth/check', { permissionCode });
}

/**
 * 用户注册
 * @param data 注册参数
 */
export async function registerApi(data: AuthApi.RegisterParams) {
  return http.post<AuthApi.RegisterResult>('/auth/register', data);
}
